package opensource.xinye.com.test11

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import opensource.xinye.com.test11.jni.Socket

class ServerUdpActivity : Activity() {
    companion object {
        fun launch(activity: Activity){
            activity.startActivity(Intent(activity,ServerUdpActivity::class.java))
        }
    }

    private lateinit var mSocketHelper: SocketHelper
    private lateinit var mSocket: Socket

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_server_udp)

        mSocket = Socket({
            mSocketHelper.logMessage(it)
        })

        mSocketHelper = SocketHelper(this,{
            startServer()
        })
    }

    private fun startServer() {
        val port = mSocketHelper.getPort()
        mSocketHelper.Task("ServerTcpTask",{
                // 执行前
            },{
                mSocketHelper.logMessage("Server Starting...")
                // 执行中 -- 后台线程
                mSocket.nativeStartUdpServer(port)

                mSocketHelper.logMessage("Server Terminated")
            },{
                // 执行后
            }).start()
    }
}